package com.alibaba.config;

import com.alibaba.model.entity.Goods;
import com.alibaba.service.GoodsService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import static com.alibaba.constants.OngoingProductSyncConstants.*;

import java.util.List;

/**
 *
 * @author ZhouYaDong
 * @date 2025/9/28
 * @description
 */

@Slf4j
@Configuration
public class GoodsBloomFilterConfig {

    @Bean
    public RBloomFilter<String> goodsBloomFilter(RedissonClient redissonClient) {
        final String BLOOM_KEY = "goods:bloomfilter";
        RBloomFilter<String> bloomFilter = redissonClient.getBloomFilter(BLOOM_KEY);
        // 如果 Redis 中不存在，则初始化
        if (!bloomFilter.isExists()) {
            bloomFilter.tryInit(100_000L, 0.01);
            log.info("[GoodsBloomFilterConfig] Bloom filter initialized with capacity 100_000 and FPR 0.01");
        }
        return bloomFilter;
    }
}
